<?php
/**
 * Albireo Kernel
 *
 * @copyright  Copyright (c) 2010 Albireo Solutions
 * @package    Kernel
 */
namespace Albireo\FileSystem;

use Nette\Object;

/**
 * UrlBuilder should simplify creating URLs with more parameters.
 * Some methods may be tailored for Google API.
 *
 * @author pavel
 */

class UrlBuilder extends Object {
    
    private $baseUrl;
    private $args = array();
    
    public function __construct($baseUrl) {
        $this->baseUrl = $baseUrl;
    }
    
    /**
     * The method takes array of string parameters and returns them as one
     * whitespace-separated string. For example, input array("a", "xyz", "albireo") 
     * should be transformed to this output: "a xyz albireo".
     * 
     * @param array(String) $params array of input parameters
     * @return String whitespace-separated input
     */
    public function separateByWhitespaces(array $params) {
        $result = "";
        foreach ($params as $value) {
            $result .= $value . " ";
        }
        return \rtrim($result);
    }
    
    
    public function addParameter($paramName, $paramValue) {
        $this->args[$paramName] = $paramValue;
    }
    
    /**
     * Builds and returns the URL represented by this UrlBuilder
     * 
     * @return String whole URL
     */
    public function build() {
        $scopeParams = \http_build_query($this->args);
        return $this->baseUrl . "?" .$scopeParams;
    }
}
